<?php
defined('IN_CMS') or die('Direct access to Script restricted.');

class Profile extends Common
{
	/**
	 * Конструктор класса
	 */
	public function __construct()
	{

	}

	/**
	 * Деструктор класса
	 */
	public function __destruct()
	{

	}
	
	/**
	 * getProfiles()
	 * 
	 * @param	int		$lang_id
	 * @param	int		$user_id
	 * @param	int		$category_id
	 * @param	int		$country_id
	 * @param	int		$zone_id
	 * @param	int		$city_id
	 * @param	bool	$top
	 * @param	bool	$pro
	 * @return	array
	 */
	public function getProfiles($lang_id, $user_id, $category_id, $country_id, $zone_id, $city_id, $top, $pro)
	{
		$profiles = array();
		
		return $profiles;
	}
	
	/**
	 * getProfilesCategories()
	 * 
	 * @param	int		$lang_id
	 * @param	int		$parent_id
	 * @param	int		$level
	 */
	public function getProfilesCategories($lang_id, $parent_id, $level)
	{
		//
		$parameters = array(
			'lang_id' => $lang_id, 
			'parent_id' => $parent_id, 
			'level' => $level
		);
		
		//
		$sql = self::$obj_functions->getSQL('profiles_getcategories', $parameters);
		//self::$obj_error->showMessage($sql, 3);
		$result = self::$obj_db->sql_query($sql) or self::$obj_error->showMessageSQL(__FUNCTION__, basename(__FILE__), __LINE__);
		$categories = self::$obj_db->sql_fetchrowset($result);
		
		unset($lang_id, $sql, $parameters, $result);
		return $categories;
	}
	
	/**
	 * getProfileCategoryByCode()
	 * 
	 * @param	string	$code
	 * @param	int		$parent_id
	 * @return	int		$category_id
	 */
	public function getProfileCategoryByCode($code, $parent_id = 0)
	{
		$category_id = 0;
		
		//
		$sql = "SELECT 
					category_id 
				FROM 
					" . TABLE_PREFIX . "profiles_categories 
				WHERE 
					code = " . self::$obj_functions->toMySQL($code) . " 
					AND 
					parent_id = " . (int)$parent_id . " 
				LIMIT 1";
		
		//self::$obj_error->showMessage($sql, 3);
		$result = self::$obj_db->sql_query($sql) or self::$obj_error->showMessageSQL(__FUNCTION__, basename(__FILE__), __LINE__);
		if (self::$obj_db->sql_numrows($result) > 0)
		{
			$row = self::$obj_db->sql_fetchrow($result);
			$category_id = (int)$row['category_id'];
		}
		
		self::$obj_db->sql_freeresult($result);
		unset($code, $result, $row, $sql);
		
		return $category_id;
	}
	
	/**
	 * getProfileCategoryByID()
	 *
	 * @param	int		$lang_id
	 * @param	int		$category_id
	 */
	public function getProfileCategoryByID($lang_id, $category_id)
	{
		$category = array();

		//
		$sql = "SELECT
					c.category_id, 
					c.code, 
					c.category_url, 
					c.parent_id, 
					c.level, 
					c.icon, 
					c.image, 
					c.rating, 
					c.profiles_counter, 
					cl.category_name, 
					cl.category_description, 
					cl.meta_title, 
					cl.meta_description, 
					cl.meta_keywords 
				FROM
					" . TABLE_PREFIX . "profiles_categories AS c
				LEFT JOIN
					" . TABLE_PREFIX . "profiles_categories_lang AS cl
				ON
					c.category_id = cl.category_id
					AND
					cl.lang_id = " . (int)$lang_id . "
				WHERE
					c.category_id = " . (int)$category_id . " 
				LIMIT 1";

		//self::$obj_error->showMessage($sql, 3);
		$result = self::$obj_db->sql_query($sql) or self::$obj_error->showMessageSQL(__FUNCTION__, basename(__FILE__), __LINE__);
		if ( self::$obj_db->sql_numrows($result) > 0 )
		{
			$row = self::$obj_db->sql_fetchrow($result);

			$category['category_id']			= (int)$row['category_id'];
			$category['code']					= self::$obj_functions->toHTML($row['code']);
			$category['category_url']			= self::$obj_functions->toHTML($row['category_url']);
			$category['parent_id']				= (int)$row['parent_id'];
			$category['level']					= (int)$row['level'];
			$category['icon']					= self::$obj_functions->toHTML($row['icon']);
			$category['image']					= self::$obj_functions->toHTML($row['image']);
			$category['rating']					= (float)$row['rating'];
			$category['profiles_counter']		= (int)$row['profiles_counter'];
			$category['category_name']			= self::$obj_functions->toHTML($row['category_name']);
			$category['category_description']	= self::$obj_functions->toHTML($row['category_description']);
			$category['meta_title']				= self::$obj_functions->toHTML($row['meta_title']);
			$category['meta_description']		= self::$obj_functions->toHTML($row['meta_description']);
			$category['meta_keywords']			= self::$obj_functions->toHTML($row['meta_keywords']);
		}

		self::$obj_db->sql_freeresult($result);
		unset($sql, $result, $row, $category_id);

		return $category;
	}
}
?>
